<title>访客列表</title>


<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href=""></a>
        <a><cite>访客列表</cite></a>
    </div>
</div>


<!--<style>-->
<!--    #organizationTreeBar {-->
<!--        padding: 10px 15px;-->
<!--        border: 1px solid #e6e6e6;-->
<!--        background-color: #f2f2f2;-->
<!--    }-->
<!--    .layui-table-cell img{-->
<!--        height: 28px;-->
<!--    }-->
<!--</style>-->

<!--<script type="text/html" template>-->
<!--    <link rel="stylesheet" href="{{ layui.setter.paths.base }}style/template.css?v={{ layui.admin.v }}-1" media="all">-->
<!--</script>-->


<div class="layui-fluid">


    <!-- 内容 -->
    <div class="body-content" style="visibility: visible;">

<!--        <link rel="stylesheet" href="__STATIC__/common.css">-->
        <link rel="stylesheet" href="__STATIC__/order.css">
        <link rel="stylesheet" href="__STATIC__/package.css">

        <!-- 订单详情、订单状态 -->
        <div class="layui-card card-common card-brief order-detail">
            <div class="layui-card-header">
                <span class="card-title">订单详情</span>
            </div>
            <div class="order-information order-information-bottom layui-card-body">
                <div class="order-information-contentOne">
                    <div class="contentOne-content">
                        <div class="contentOne-content-title">交易流水号：</div>
                        <div class="contentOne-content-text text-num">1732519495352311000</div>
                    </div>
                    <div class="contentOne-content">
                        <div class="contentOne-content-title">订单编号：</div>
                        <div class="contentOne-content-text text-num">2024112515241002</div>
                    </div>
                    <div class="contentOne-content">
                        <div class="contentOne-content-title">订单类型：</div>
                        <div class="contentOne-content-text">普通订单</div>
                    </div>
                    <div class="contentOne-content">
                        <div class="contentOne-content-title">订单来源：</div>
                        <div class="contentOne-content-text">H5</div>
                    </div>
                    <div class="contentOne-content">
                        <div class="contentOne-content-title">买家：</div>
                        <div class="contentOne-content-text">13000001111</div>
                    </div>
                </div>
                <div class="order-information-contentTwo">
                    <div class="contentOne-content">
                        <div class="contentOne-content-title">配送方式：</div>
                        <div class="contentOne-content-text">快递发货</div>
                    </div>
                    <div class="contentOne-content">
                        <div class="contentOne-content-title">收货人：</div>
                        <div class="contentOne-content-text">asdas</div>
                    </div>
                    <div class="contentOne-content">
                        <div class="contentOne-content-title">联系电话：</div>
                        <div class="contentOne-content-text">13000001111</div>
                    </div>
                    <div class="contentOne-content">
                        <div class="contentOne-content-title">收货地址：</div>
                        <input type="text" class="address" id="address" value="北京市-北京市-东城区-11111">
                        <div class="contentOne-content-text contentOne-content-text-die" title="北京市-北京市-东城区-11111">北京市-北京市-东城区-11111</div>
                        <div class="copy-icon-box"><a href="javascript:ns.copy('address');" class="iconfont iconfuzhi" style="margin-top: 4px"></a></div>
                    </div>
                </div>
                <div class="order-information-contentTwo">
                    <div class="contentOne-content">
                        <div class="contentOne-content-title">营销活动：</div>
                        <div class="contentOne-content-text">-</div>
                    </div>
                    <div class="contentOne-content">
                        <div class="contentOne-content-title">买家留言：</div>
                        <div class="contentOne-content-text contentOne-content-text-die">
                            3									</div>
                    </div>
                    <div class="contentOne-content">
                        <div class="contentOne-content-title">备注：</div>
                        <div class="contentOne-content-text">
                            25									</div>
                    </div>
                </div>
            </div>
            <div class="layui-card-header">
                <span class="card-title">订单状态</span>
            </div>
            <div class="order-information-contentOne order-orderStatus-contentOne layui-card-body">
                <div class="contentOne-content">
                    <div class="contentOne-content-title">订单状态：</div>
                    <div class="contentOne-content-text contentOne-content-textNew">已关闭</div>
                </div>
                <div class="contentTow-operation">
                    <div class="contentTow-operation-content bg-color-light-9 contentTow-operation-new" onclick="orderRemark('3')">备注</div>
                    <a class="contentTow-operation-content bg-color-light-9 contentTow-operation-new bg-color-light-9" href="javascript:orderAction('orderDelivery', '3')">发货</a>
                    <a class="contentTow-operation-content bg-color-light-9 contentTow-operation-new bg-color-light-9" href="javascript:orderAction('orderAddressUpdate', '3')">修改地址</a>
                    <a class="contentTow-operation-content bg-color-light-9 contentTow-operation-new bg-color-light-9" href="javascript:printDeliverOrder('3');">打印发货单</a>
                    <a class="contentTow-operation-content bg-color-light-9 contentTow-operation-new bg-color-light-9" href="javascript:orderPrintElectronicsheet('3');">打印电子面单</a>
                </div>
                <div class="orderStatus">
                    <div class="orderStatus-content-title">提醒：</div>
                    <div class="orderStatus-content-text">
                        <p class="text-tile">买家付款成功后，货款将直接进入您的商户号（微信、支付宝）</p>
                        <p class="text-tile">请及时关注你发出的包裹状态，确保可以配送至买家手中</p>
                        <p class="text-tile">如果买家表示没收到货或货物有问题，请及时联系买家处理，友好协商</p>
                    </div>
                </div>
            </div>


        </div>


        <!-- 商品信息、订单操作日志 -->
        <div class="shop-information layui-card card-common card-brief">
            <div class="layui-card-header">
                <span class="card-title">商品信息</span>
            </div>
            <div class="shop-information-table layui-card-body">
                <table lay-filter="parse-table-order-product" lay-skin="line">
                    <thead>
                    <tr class="table-trOne">
                        <th lay-data="{field:'product_name', width:200}">商品</th>
                        <th lay-data="{field:'price'}">价格</th>
                        <th lay-data="{field:'sku_no'}">商品编码</th>
                        <th lay-data="{field:'sale_num'}">数量</th>
                        <th lay-data="{field:'total_money'}">小计（元）</th>
                        <th lay-data="{field:'refund_status'}">退款状态</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr class="table-trTow">
                        <td>演示商品一 33333333</td>
                        <td>11.00</td>
                        <td></td>
                        <td>5</td>
                        <td>55.00</td>
                        <td>
                        </td>
                    </tr>
                    </tbody>
                </table>
                <div class="table-trThree table-trFour">
                    <div>
                        <p>商品总额：<span>￥55.00</span></p>
                    </div>
                    <div>
                        <p>店铺优惠券：<span>￥1.00</span></p>
                    </div>
                    <div>
                        <p>店铺优惠：<span>￥0.00</span></p>
                    </div>

                    <div>
                        <p>订单调价：<span>￥20.00</span></p>
                    </div>
                    <div>
                        <p>配送费用：<span>￥0.00</span></p>
                    </div>
                    <div>
                        <p>发票费用：<span>￥0.00</span></p>
                    </div>
                    <div>
                        <p>发票邮寄费用：<span>￥0.00</span></p>
                    </div>
                </div>
                <div class="table-settlement">
                    订单共<span>5</span>件商品,共计<span>￥74.00</span>
                </div>
            </div>
        </div>

        <!-- 订单操作 -->
        <div class="shop-operation layui-card card-common card-brief">
            <div class="layui-card-header">
                <span class="card-title">订单操作日志</span>
            </div>
            <div class="shop-operation-time layui-card-body">
                <ul class="layui-timeline">
                    <li class="layui-timeline-item">
                        <div class="layui-time-left">
                            <p>2024-11-25</p>
                            <p>16:20:35</p>
                        </div>
                        <div class="layui-icon layui-timeline-axis">
                            <span class="layui-icon-center"></span>
                        </div>
                        <div class="layui-timeline-content layui-text">
                            <div class="layui-timeline-title">长时间未支付,订单自动关闭</div>
                        </div>
                    </li>
                    <li class="layui-timeline-item">
                        <div class="layui-time-left">
                            <p>2024-11-25</p>
                            <p>15:25:26</p>
                        </div>
                        <div class="layui-icon layui-timeline-axis">
                            <span class="layui-icon-center"></span>
                        </div>
                        <div class="layui-timeline-content layui-text">
                            <div class="layui-timeline-title">商家备注了订单，备注内容：25</div>
                        </div>
                    </li>
                    <li class="layui-timeline-item">
                        <div class="layui-time-left">
                            <p>2024-11-25</p>
                            <p>15:24:55</p>
                        </div>
                        <div class="layui-icon layui-timeline-axis">
                            <span class="layui-icon-center"></span>
                        </div>
                        <div class="layui-timeline-content layui-text">
                            <div class="layui-timeline-title">买家【13000001111】下单了</div>
                        </div>
                    </li>
                </ul>
            </div>
        </div>

        <script type="text/javascript">
            var laytpl;
            var form;
            var order_list = [];
            var express_company_list = [];
            var deliyer_list = [];
            var printer_addon_is_exit = '0';
            var isTradeManaged = false; // 微信小程序是否已开通发货信息管理服务

            function reloadList(){
                listenerHash(); // 刷新页面
                layer.closeAll();
            }

            //渲染模板引擎
            layui.use(['laytpl','form'], function(){
                laytpl = layui.laytpl;
                form = layui.form;
                $ = layui.$;
                form.render();

                // $(function () {
                //     // 获取物流公司
                //     $.ajax({
                //         type: "post",
                //         url: ("shop/express/getShopExpressCompanyList"),
                //         dataType: 'json',
                //         success: function (res) {
                //             if (res.code == 0) {
                //                 express_company_list = res.data;
                //             }
                //         }
                //     });
                //
                //     // 获取配送员
                //     $.ajax({
                //         type: "post",
                //         url: ("shop/local/getDeliverList"),
                //         dataType: 'json',
                //         success: function (res) {
                //             if (res.code == 0) {
                //                 deliyer_list = res.data;
                //             }
                //         }
                //     });
                //
                //     getOrderShippingIsTradeManaged();
                //
                // });


                setOrderInfo([{"order_id":5,"order_no":"2024112515241002","site_id":1,"site_name":"\u7f51\u7ad9\u6807\u9898","website_id":0,"order_name":"\u6f14\u793a\u5546\u54c1\u4e00 33333333","order_from":"h5","order_from_name":"H5","order_type":1,"order_type_name":"\u666e\u901a\u8ba2\u5355","order_promotion_type":0,"order_promotion_name":"","promotion_id":0,"out_trade_no":"1732519495352311000","out_trade_no_2":"","delivery_code":"","order_status":-1,"order_status_name":"\u5df2\u5173\u95ed","order_status_action":"{\"status\":-1,\"name\":\"\u5df2\u5173\u95ed\",\"is_allow_refund\":0,\"icon\":\"public\\\/uniapp\\\/order\\\/order-icon-close.png\",\"action\":[],\"member_action\":[],\"color\":\"\"}","pay_status":0,"delivery_status":0,"refund_status":0,"pay_type":"","pay_type_name":"","delivery_type":"express","delivery_type_name":"\u5feb\u9012\u53d1\u8d27","member_id":1,"name":"asdas","mobile":"13000001111","telephone":"13000001111","province_id":110000,"city_id":110100,"district_id":110101,"community_id":0,"address":"11111","full_address":"\u5317\u4eac\u5e02-\u5317\u4eac\u5e02-\u4e1c\u57ce\u533a","longitude":"0","latitude":"0","buyer_ip":"127.0.0.1","buyer_ask_delivery_time":"","buyer_message":"3","goods_money":"55.00","delivery_money":"0.00","promotion_money":"0.00","coupon_id":1,"coupon_money":"1.00","invoice_money":"0.00","order_money":"74.00","adjust_money":"20.00","balance_money":"0.00","pay_money":"74.00","create_time":1732519495,"pay_time":0,"delivery_time":0,"sign_time":0,"finish_time":0,"close_time":1732522835,"is_lock":0,"is_evaluate":0,"is_delete":0,"is_enable_refund":0,"remark":"25","goods_num":5,"delivery_store_id":0,"delivery_status_name":"","is_settlement":0,"store_settlement_id":0,"delivery_store_name":"","promotion_type":"","promotion_type_name":"","promotion_status_name":"","delivery_store_info":"","virtual_code":"","evaluate_status":0,"evaluate_status_name":"","refund_money":"0.00","commission":"0.00","is_invoice":0,"invoice_type":1,"invoice_title":"","taxpayer_number":"","invoice_rate":"0.00","invoice_content":"","invoice_delivery_money":"0.00","invoice_full_address":"","is_tax_invoice":0,"invoice_email":"","invoice_title_type":0,"is_fenxiao":1,"point_money":"0.00","member_card_money":"0.00","member_card_order":0,"invoice_status":0,"invoice_remark":null,"invoice_code":"","invoice_image":"","invoice_time":0,"predict_delivery_time":0,"is_video_number":0,"close_cause":"\u957f\u65f6\u95f4\u672a\u652f\u4ed8,\u8ba2\u5355\u81ea\u52a8\u5173\u95ed","cashier_order_type":"","cashier_sell_time":0,"cashier_operator_id":0,"cashier_operator_name":"","balance":"0.00","total_balance":"0.00","store_id":0,"reduction":"0.00","round_money":"0","order_scene":"online","store_commission_rate":"0.00","store_commission":"0.00","delivery_start_time":0,"delivery_end_time":0,"store_name":null,"nickname":"13000001111","verifier_name":"","order_goods":[{"order_goods_id":6,"order_id":5,"order_no":"2024112515241002","site_id":1,"member_id":1,"goods_id":1,"sku_id":5,"sku_name":"\u6f14\u793a\u5546\u54c1\u4e00 33333333","sku_image":"public\/static\/img\/default_img\/square.png","sku_no":"","is_virtual":0,"goods_class":"1","goods_class_name":"\u5b9e\u7269\u5546\u54c1","price":"11.00","cost_price":"0.00","num":5,"goods_money":"55.00","cost_money":"0.00","delivery_status":0,"delivery_status_name":"\u5f85\u53d1\u8d27","delivery_no":"","gift_flag":0,"refund_no":"","refund_status":0,"refund_status_name":"","refund_status_action":"","refund_type":0,"refund_apply_money":"0.00","refund_reason":"","refund_real_money":"0.00","refund_delivery_name":"","refund_delivery_no":"","refund_time":0,"refund_refuse_reason":"","refund_action_time":0,"real_goods_money":"74.00","refund_remark":"","refund_delivery_remark":"","refund_address":"","is_refund_stock":0,"refund_money_type":1,"shop_refund_remark":"","shop_active_refund":0,"shop_active_refund_no":"","shop_active_refund_remark":"","shop_active_refund_money":"0.00","shop_active_refund_money_type":1,"refund_mode":1,"promotion_money":"0.00","coupon_money":"1.00","adjust_money":"20.00","goods_name":"\u6f14\u793a\u5546\u54c1\u4e00","sku_spec_format":"[{\"spec_id\":-983,\"spec_name\":\"111111\",\"spec_value_id\":-1524,\"spec_value_name\":\"33333333\",\"image\":\"\"}]","is_fenxiao":1,"use_point":0,"point_money":"0.00","refund_delivery_money":"0.00","create_time":0,"out_aftersale_id":"","refund_address_id":0,"refund_pay_money":"0.00","store_id":0,"card_item_id":0,"card_promotion_money":"0.00","supplier_id":0,"is_adjust_price":0}],"package_list":[],"order_log":[{"id":11,"order_id":5,"action":"\u957f\u65f6\u95f4\u672a\u652f\u4ed8,\u8ba2\u5355\u81ea\u52a8\u5173\u95ed","uid":0,"nick_name":"\u7cfb\u7edf","order_status":-1,"action_way":2,"order_status_name":"\u5df2\u5173\u95ed","action_time":1732522835},{"id":9,"order_id":5,"action":"\u5546\u5bb6\u5907\u6ce8\u4e86\u8ba2\u5355\uff0c\u5907\u6ce8\u5185\u5bb9\uff1a25","uid":1,"nick_name":"admin","order_status":0,"action_way":2,"order_status_name":"\u5f85\u652f\u4ed8","action_time":1732519526},{"id":8,"order_id":5,"action":"\u4e70\u5bb6\u301013000001111\u3011\u4e0b\u5355\u4e86","uid":1,"nick_name":"13000001111","order_status":0,"action_way":1,"order_status_name":"\u5f85\u652f\u4ed8","action_time":1732519495}],"is_trade_managed":false}]);});

            /**
             ** 设置订单信息
             **/
            function setOrderInfo(temp_order_list){
                var temp = {};
                temp_order_list.forEach(item => temp[item.order_id] = item);
                order_list = temp;
            }

            /**
             ** 获取订单信息
             **/
            function getOrderInfo(order_id){
                return order_list[order_id];
            }

            /**
             * 订单操作
             * @param fun
             * @param order_id
             */
            function orderAction(fun, order_id){
                eval(fun+"("+order_id+")");
            }

            // 打印发货单
            function printDeliverOrder(order_id) {
                var url = ("shop/printer/batchprintorder", {request_mode: 'download',order_id: order_id});
                var LODOP = getLodop();
                if (LODOP) {
                    LODOP.PRINT_INIT("发货单打印");
                    LODOP.ADD_PRINT_TBURL(5, 10, "770", "95%", url);
                    LODOP.SET_PRINT_STYLEA(0, "HOrient", 3);
                    LODOP.SET_PRINT_STYLEA(0, "VOrient", 3);
                    LODOP.ADD_PRINT_TEXT(590, 680, 130, 22, "页号：第#页/共&页");
                    LODOP.SET_PRINT_STYLEA(0, "ItemType", 2);
                    LODOP.SET_PRINT_STYLEA(0, "Horient", 1);
                    LODOP.SET_PRINT_STYLEA(0, "Vorient", 1);
                    LODOP.SET_SHOW_MODE("MESSAGE_GETING_URL", ""); //该语句隐藏进度条或修改提示信息
                    LODOP.PREVIEW(); //预览
                }
            }

            // 订单备注
            function orderRemark(order_id){
                var order_info = getOrderInfo(order_id);
                layer.prompt({
                    formType: 2,
                    value: order_info.remark,
                    title: '卖家备注',
                    area: ['400px', '100px'], //自定义文本域宽高
                    yes: function(index, layero){
                        var value = layero.find(".layui-layer-input").val();
                        if(value.trim().length > 200){
                            layer.msg("备注太长，最多200个字符！");
                            return false;
                        }
                        $.ajax({
                            type: "post",
                            url: ("shop/order/orderRemark"),
                            async: true,
                            dataType: 'json',
                            data: {order_id : order_id, remark : value},
                            success: function (res) {
                                layer.msg(res.message);
                                if(res.code == 0){
                                    layer.close(layer.index - 1);
                                    reloadList();
                                }
                            }
                        })
                    }
                });

            }

            // 关闭订单
            var closeRepeat = false;
            function orderClose(order_id){
                var temp_index = layer.confirm('确定要关闭该订单吗?', function(index) {
                    if (closeRepeat) return;
                    closeRepeat = true;
                    layer.close(index);
                    $.ajax({
                        url: ("shop/order/close"),
                        data: {order_id : order_id},
                        dataType: 'JSON',
                        type: 'POST',
                        success: function(res) {
                            layer.msg(res.message);
                            if(res.code == 0){
                                layer.close(layer.index - 1);
                                reloadList();
                            }
                            closeRepeat = false;
                        }
                    });
                }, function () {
                    layer.close();
                    closeRepeat = false;
                });
            }

            /**
             * 线下支付
             * @param order_id
             */
            var payRepeat = false;
            function offlinePay(order_id){
                layer.confirm('确定要线下支付吗?', function(index) {
                    if (payRepeat) return;
                    payRepeat = true;
                    $.ajax({
                        url: ("shop/order/offlinePay"),
                        data: {order_id : order_id},
                        dataType: 'JSON',
                        type: 'POST',
                        success: function(res) {
                            layer.msg(res.message);
                            if(res.code == 0){
                                reloadList();
                            }
                            payRepeat = false;
                        }
                    });
                }, function () {
                    layer.close();
                    payRepeat = false;
                });
            }

            /**
             * 删除订单
             * @param order_id
             */
            function orderDelete(order_id){
                layer.confirm('确定要删除该订单吗?', function(index) {
                    layer.close(index);
                    $.ajax({
                        url: ("shop/order/delete"),
                        data: {order_id : order_id},
                        dataType: 'JSON',
                        type: 'POST',
                        success: function(res) {
                            layer.msg(res.message);
                            if(res.code == 0){
                                reloadList();
                            }
                        }
                    });
                }, function () {
                    layer.close();
                });
            }

            /**
             * 确认收货
             * @param order_id
             * @param type
             */
            function takeDelivery(order_id, type = 0){
                var html = "";
                if(type == 0){
                    html = '确保买家已经收到您的商品，并且与买家协商完毕提前确认收货?';
                }else{
                    html = '确保买家已经收到您的商品，并且与买家协商完毕提前确认收货?（退款中的订单及虚拟订单无法确认收货）';
                }
                layer.confirm(html, function(index) {
                    layer.close(index);
                    $.ajax({
                        url: ("shop/order/takeDelivery"),
                        data: {order_id : order_id, type : type},
                        dataType: 'JSON',
                        type: 'POST',
                        success: function(res) {
                            layer.msg(res.message);
                            if(res.code == 0){
                                reloadList();
                            }
                        }
                    });
                }, function () {
                    layer.close();
                });
            }

            // 打印订单小票
            function printTicket(order_id){
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    url: ("shop/order/printTicket"),
                    data: {order_id},
                    success: function (res) {
                        if (res.code != 0) {
                            layer.msg(res.message ? res.message : '小票打印失败');
                        }
                    }
                });
            }

            // 查询小程序是否已开通发货信息管理服务
            function getOrderShippingIsTradeManaged() {
                $.ajax({
                    type: "post",
                    url: ("shop/order/orderShippingIsTradeManaged"),
                    dataType: 'json',
                    success: function (res) {
                        if (res.code == 0) {
                            isTradeManaged = res.data;
                        }
                    }
                });
            }

        </script>
        <!-- 修改订单价格 -->
        <!-- 调整价格模态 -->
        <script type="text/html" id="adjust_price_html">
            <div style="padding:10px;">
                <div class="layui-form adjust-price-html" id='adjust_price'lay-filter="adjust_price">
                    <div style="color: #666;">注意 : 只有订单未付款时才支持改价,改价后请联系买家刷新订单核实订单金额后再支付。</div>
                    <table class="layui-table">
                        <colgroup>
                            <col width="10%">
                            <col width="4%">
                            <col width="6%">
                            <col width="4%">
                            <col width="9%">
                            <col width="4%">
                            <col width="8%">
                            <col width="8%">
                            <col width="9%">
                            <col width="10%">
                            <col width="10%">
                            <col width="10%">
                            <col width="6%">
                        </colgroup>
                        <thead>
                        <tr>
                            <th>商品信息</th>
                            <th>单价</th>
                            <th>数量</th>
                            <th>小计</th>
                            <th>商品总额</th>
                            <th>优惠</th>
                            <th>优惠券</th>
                            <th>积分抵现</th>
                            <th>发票费用</th>
                            <th>发票邮寄费用</th>
                            <th>调整金额</th>
                            <th>运费</th>
                            <th>总计</th>
                        </tr>
                        </thead>
                        <tbody>
                        {{# layui.each(d.order_goods, function(index, item){ }}
                        <tr data-order_money="{{ d.order_money }}"data-adjust_money="{{ d.adjust_money }}"data-delivery_money="{{ d.delivery_money }}"
                            data-promotion_money="{{ d.promotion_money }}" data-coupon_money="{{ d.coupon_money }}" data-goods_money="{{ d.goods_money }}"
                            data-adjust_money="{{ d.adjust_money }}"data-delivery_money="{{ d.delivery_money }}" data-invoice_rate="{{ d.invoice_rate }}"
                            data-invoice_delivery_money="{{ d.invoice_delivery_money }}"  data-is_invoice="{{ d.is_invoice }}" data-point_money="{{ d.point_money }}" >
                            <td>{{ item.sku_name }}</td>
                            <td>{{ item.price }}</td>
                            <td>{{ item.num }}</td>
                            <td>{{ item.goods_money }}</td>
                            {{#  if(index == 0){ }}
                            <td rowspan="{{ d.order_goods.length }}">{{ d.goods_money }}</td>
                            <td rowspan="{{ d.order_goods.length }}">{{ d.promotion_money }}</td>
                            <td rowspan="{{ d.order_goods.length }}">{{ d.coupon_money }}</td>
                            <td rowspan="{{ d.order_goods.length }}">{{ d.point_money }}</td>
                            <td rowspan="{{ d.order_goods.length }}" class="adjust-invoice-money">{{ d.invoice_money }}</td>
                            <td rowspan="{{ d.order_goods.length }}" class="adjust-invoice-delivery-money">{{ d.invoice_delivery_money }}</td>
                            <td rowspan="{{ d.order_goods.length }}"><input type="number" name="adjust_money" min="{{ d.goods_money - d.promotion_money - d.coupon_money }}" class="layui-input adjust-money" onchange="adjustChange(this);" value="{{ d.adjust_money }}"/></td>
                            <td rowspan="{{ d.order_goods.length }}"><input type="number"  name="delivery_money" class="layui-input delivery-money" onchange="adjustChange(this);" value="{{ d.delivery_money }}"/></td>
                            <td rowspan="{{ d.order_goods.length }}" class="adjust-pay-money">{{ d.order_money }}</td>
                            {{#  } }}
                        </tr>
                        {{#  }); }}
                        </tbody>
                    </table>
                    <div style="color: #666;">
                        <p><a class="text-color">实际商品金额</a> = 商品总额 - 优惠金额 - 优惠券金额 - 积分抵现 + 调价</p>
                        <p><a class="text-color">发票费用</a> = 实际商品金额 * 发票比率</p>
                        <p>订单总额 = <a class="text-color">实际商品金额</a> + <a class="text-color">发票费用</a> + 运费 +  发票邮寄费用</p>
                    </div>

                    <input type="hidden" name="order_id" value="{{ d.order_id }}"/>
                    <button class="layui-btn"  lay-submit id="submit_price" lay-filter="submit_price" style="display:none;">保存</button>
                </div>
            </div>
        </script>

        <script>
            var form;
            // 订单调价
            function orderAdjustMoney(order_id) {
                var order_info = getOrderInfo(order_id);
                var getTpl = $("#adjust_price_html").html();
                laytpl(getTpl).render(order_info, function (html) {
                    layer.open({
                        type: 1,
                        shadeClose: true,
                        shade: 0.3,
                        offset: 'auto',
                        scrollbar: true,
                        fixed: false,
                        title: "调整价格",
                        area: ['1250px', 'auto'],
                        btn: ['确定', '取消'],
                        yes: function (index, layero) {
                            $("#submit_price").click();
                        },
                        btn2: function (index, layero) {
                            layer.close(index);
                        },
                        content: html,
                        success: function (layero, index) {
                            var repeat_flag = false;//防重复标识
                            form.render();
                            form.on('submit(submit_price)', function (data) {
                                if (repeat_flag) return;
                                repeat_flag = true;

                                $.ajax({
                                    url: ("shop/order/adjustPrice"),
                                    type: "POST",
                                    dataType: "JSON",
                                    async: false,
                                    data: data.field,
                                    success: function (res) {
                                        layer.msg(res.message);
                                        if (res.code == 0) {
                                            layer.close(layer.index - 1);
                                            reloadList();
                                        } else {
                                            repeat_flag = false;
                                        }

                                    }
                                });
                                return false;
                            });
                        }
                    });
                    form.render();
                });
            }

            function adjustChange(obj){
                var adjust_money = 0;
                var delivery_money = 0;
                var parent_obj = $(obj).parent().parent();
                var o_order_money = parent_obj.attr("data-order_money");
                var o_adjust_money = parent_obj.attr("data-adjust_money");
                var o_delivery_money = parent_obj.attr("data-delivery_money");
                var invoice_delivery_money = parent_obj.attr("data-invoice_delivery_money");
                var promotion_money = parent_obj.attr("data-promotion_money");
                var coupon_money = parent_obj.attr("data-coupon_money");
                var goods_money = parent_obj.attr("data-goods_money");
                var is_invoice = parent_obj.attr("data-is_invoice");
                var point_money = parent_obj.attr("data-point_money");
                $(".adjust-money").each(function(){
                    adjust_money += parseFloat($(this).val());
                });
                $(".delivery-money").each(function(){
                    delivery_money += parseFloat($(this).val());
                });
                var real_goods_money = parseFloat(goods_money) - parseFloat(promotion_money) - parseFloat(coupon_money) + parseFloat(adjust_money) - parseFloat(point_money);
                var invoice_rate = is_invoice == 1 ? parent_obj.attr("data-invoice_rate") : 0;
                var invoice_money = Math.round(parseFloat(real_goods_money) * parseFloat(invoice_rate)/100 * 100) / 100;
                var total_money = parseFloat(goods_money) - parseFloat(promotion_money) - parseFloat(coupon_money) - parseFloat(point_money) + parseFloat(adjust_money) + parseFloat(invoice_delivery_money) + parseFloat(invoice_money) + parseFloat(delivery_money)
                total_money = Math.round(total_money * 100) / 100;
                $(obj).parent().parent().find(".adjust-invoice-money").text(invoice_money);
                // $(obj).parent().parent().find(".adjust-invoice-delivery-money").text(total_money);
                // var total_money = parseFloat(o_order_money) - parseFloat(o_adjust_money) - parseFloat(o_delivery_money) + parseFloat(adjust_money) + parseFloat(delivery_money);
                $(".adjust-pay-money").html(total_money);
            }
        </script>
        <!-- 修改订单收货地址 -->
        <!-- 修改订单收货地址 -->
        <!--<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.4.6&amp;key=2df5711d4e2fd9ecd1622b5a53fc6b1d"></script>-->
        <!--<script type="text/javascript" src="http://niu.co/public/static/js/map_address.js"></script>-->
        <script type="text/javascript" src="__STATIC__/address.js"></script>

        <style>
            .update-address-html .order-map{width:876px;height:380px;}
        </style>

        <!-- 修改收货地址模态 -->
        <div id="update_address_box" class="update-address-box"></div>
        <script type="text/html" id="update_address_html">

            <div class="layui-form update-address-html" id='update_address'lay-filter="update_address">
                <input type="hidden" name="order_id" value="{{ d.order_id }}"/>
                <!--自提点地址-->
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="required">* </span>收货地址</label>
                    <div class="layui-input-inline area-select">
                        <select name="province_id" lay-filter="province_id" lay-verify="province_id">
                            <option value="">请选择省份</option>
                        </select>
                    </div>
                    <div class="layui-input-inline area-select">
                        <select name="city_id"  lay-filter="city_id" lay-verify="city_id">
                            <option value="">请选择城市</option>
                        </select>
                    </div>
                    <div class="layui-input-inline area-select">
                        <select name="district_id"  lay-filter="district_id" lay-verify="district_id">
                            <option value="">请选择区/县</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-inline" >
                        <input type="text" name="address"  placeholder="请填写具体地址。" lay-verify="required" autocomplete="off" class="layui-input address-content len-long" value="{{# if(d.address != undefined){}}{{ d.address}}{{#  } }}">
                        {{# if(d.order_type == 3){ }}
                        <input type = "hidden" name="longitude" lay-verify="required" class="layui-input" value="{{# if(d.longitude != undefined){}}{{ d.longitude}}{{#  } }}"/>
                        <input type = "hidden" name="latitude" lay-verify="required" class="layui-input" value="{{# if(d.latitude != undefined){}}{{ d.latitude}}{{#  } }}"/>
                        {{# } }}
                    </div>
                    {{# if(d.order_type == 3){ }}
                    <button class='layui-btn-primary layui-btn' onclick="refreshFrom();">查找地址</button>
                    {{# } }}
                </div>
                {{# if(d.order_type == 3){ }}
                <!--地图定位-->
                <div class="layui-form-item">
                    <label class="layui-form-label">地图定位</label>
                    <div class="layui-input-block special-length">
                        <div id="container" class="order-map"></div>
                    </div>
                </div>
                {{# } }}
                <!--联系人方式-->
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">收货人</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" lay-verify="required" placeholder="请填写收货联系人" autocomplete="off" class="layui-input selffetch-input len-mid" value="{{# if(d.name != undefined){}}{{ d.name}}{{#  } }}">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">手机号码</label>
                        <div class="layui-input-block">
                            <input type="text" name="mobile" lay-verify="phone" placeholder="请填写手机号码" autocomplete="off" class="layui-input selffetch-input len-mid" value="{{# if(d.mobile != undefined){}}{{d.mobile }}{{#  } }}">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">固定号码</label>
                        <div class="layui-input-block">
                            <input type="text" name="telephone" placeholder="请填写固定号码" autocomplete="off" class="layui-input selffetch-input len-mid" value="{{# if(d.telephone != undefined){}}{{d.telephone }}{{#  } }}">
                        </div>
                    </div>
                </div>
                <button class="layui-btn"  lay-submit id="submit_address" lay-filter="submit_address" style="display:none;">保存</button>
            </div>
        </script>
        <script>
            var map_class, form,latlng;
            // 订单地址修改
            function orderAddressUpdate(order_id) {
                var order_info = getOrderInfo(order_id);
                var getTpl = $("#update_address_html").html();
                var order_data = order_info;
                laytpl(getTpl).render(order_data, function(html) {
                    layer.open({
                        type: 1,
                        shadeClose: true,
                        shade: 0.3,
                        offset: 'auto',
                        scrollbar: true,
                        fixed: false,
                        title: "编辑收货地址",
                        area: ['1200px'],
                        btn: ['确定', '取消'],
                        yes: function(index, layero){
                            $("#submit_address").click();
                        },
                        btn2: function(index, layero){
                            layer.close(index);
                        },
                        content:  html,
                        success: function(layero, index){
                            form.render();
                            //初始化省级地址
                            getAreaList(0, 1);
                            var repeat_flag = false;//防重复标识
                            form.render();
                            var initdata = {province_id : order_data.province_id, city_id : order_data.city_id, district_id : order_data.district_id};
                            initAddress(initdata, "update_address");

                            if(order_data.order_type == 3) {
                                if ($.isEmptyObject(order_data) == true) {
                                    latlng = {lat: '', lng: ''};
                                } else {
                                    latlng = {lat: order_data.latitude, lng: order_data.longitude};
                                }

                                if($("#container").length) {
                                    setTimeout(function () {
                                        map_class = new mapClass("container", latlng);
                                    },200);
                                }
                            }
                            form.render();

                            form.on('submit(submit_address)', function(data){

                                if(data.field.province_id == ''){
                                    layer.msg('请选择省份', {icon: 5, anim: 6});
                                    return;
                                }
                                if(data.field.city_id == ''){
                                    layer.msg('请选择城市', {icon: 5, anim: 6});
                                    return;
                                }
                                if(data.field.district_id == ''){
                                    layer.msg('请选择区/县', {icon: 5, anim: 6});
                                    return;
                                }
                                if(data.field.address == ''){
                                    layer.msg('请输入详细地址', {icon: 5, anim: 6});
                                    return;
                                }
                                //外卖订单修改地址必须选坐标
                                if(order_data.order_type == 3){
                                    if(data.field.latitude == '' || data.field.longitude == ''  ){
                                        layer.msg('外卖订单必须选择地图坐标', {icon: 5, anim: 6});
                                        return;
                                    }
                                }
                                var province_name = $("option[value='" + data.field.province_id + "']").text();
                                var city_name = $("option[value='" + data.field.city_id + "']").text();
                                var district_name = $("option[value='" + data.field.district_id + "']").text();
                                // var community_name = $("option[value='" + data.field.community_id + "']").text();
                                data.field.province_name = province_name;
                                data.field.city_name = city_name;
                                data.field.district_name = district_name;
                                // data.field.community_name = community_name;
                                data.field.full_address = province_name + '-' + city_name + '-' + district_name;

                                if(repeat_flag)return;
                                repeat_flag = true;
                                $.ajax({
                                    url: ("shop/order/editaddress"),
                                    type: "POST",
                                    dataType: "JSON",
                                    async: false,
                                    data: data.field,
                                    success: function (res) {
                                        layer.msg(res.message);
                                        if(res.code == 0){
                                            layer.close(layer.index - 1);
                                            reloadList();
                                        }else{
                                            repeat_flag = false;
                                        }
                                    }
                                });
                                return false;
                            });
                        }
                    });
                    form.render();
                });

            }

            /**
             * 重新渲染表单
             */
            function refreshFrom(){
                form.render();
                orderAddressChange();//改变地址
                map_class.mapChange();
            }

            //动态改变订单地址赋值
            function orderAddressChange(){
                map_class.address.province = $("select[name=province_id]").val();
                map_class.address.province_name = $("select[name=province_id] option:selected").text();
                map_class.address.city = $("select[name=city_id]").val();
                map_class.address.city_name = $("select[name=city_id] option:selected").text();
                map_class.address.district = $("select[name=district_id]").val();
                map_class.address.district_name = $("select[name=district_id] option:selected").text();
                // map_class.address.township = $("select[name=community_id]").val();
                // map_class.address.township_name = $("select[name=community_id] option:selected").text();
                map_class.address.detail_address = $("input[name=address]").val()
            }

            /**
             * 地址下拉框（主要用于坐标记录）
             */
            function selectCallBack(){
                $("input[name=longitude]").val(map_class.address.longitude);//坐标
                $("input[name=latitude]").val(map_class.address.latitude);//坐标
                $("input[name=address]").val(map_class.address.address);//详细地址
            }

            //地图点击回调时间
            function mapChangeCallBack(){
                $("input[name=address]").val(map_class.address.address);//详细地址
                $("input[name=longitude]").val(map_class.address.longitude);//坐标
                $("input[name=latitude]").val(map_class.address.latitude);//坐标
                $.ajax({
                    type : "post",
                    url : ("shop/address/getGeographicId"),
                    dataType: 'json',
                    async : true,
                    data : {
                        "address" : map_class.address.area
                    },
                    success : function(data) {
                        map_class.address.province = data.province_id;
                        map_class.address.city = data.city_id;
                        map_class.address.district = data.district_id;
                        // map_class.address.township = data.community_id;
                        map_class.map_change = false;
                        form.val("update_address", {
                            "province_id": data.province_id // "name": "value"
                        });
                        $("select[name=province_id]").change();
                        form.val("update_address", {
                            "city_id": data.city_id // "name": "value"
                        });
                        $("select[name=city_id]").change();
                        form.val("update_address", {
                            "district_id": data.district_id // "name": "value"
                        });
                        $("select[name=district_id]").change();
                        // form.val("update_address", {
                        //     "community_id": data.community_id // "name": "value"
                        // });
                        refreshFrom();//重新渲染form
                        map_class.map_change = true;
                    }
                })
            }
        </script>

        <!-- 门店自提  提货 -->
        <script>
            /**
             * 直接提货
             * @param order_id
             */
            function storeOrderTakedelivery(order_id){
                layer.confirm('确定要直接提货吗?', {title:'提示'},function(index) {
                    layer.close(index);
                    $.ajax({
                        url: ("shop/storeorder/storeOrderTakedelivery"),
                        data: {order_id : order_id},
                        dataType: 'JSON',
                        type: 'POST',
                        success: function(res) {
                            layer.msg(res.message);
                            if(res.code == 0){
                                reloadList();
                            }
                        }
                    });
                }, function () {
                    layer.close();
                });
            }
        </script>
        <!-- 发货 -->
        <!-- 订单物流发货 -->
        <style>
            .layui-table-body {
                overflow: unset;
            }

            .delivery-content {
                padding: 7px 0 !important;
            }

            .layui-table-view {
                border-top: 1px solid #eee;
                border-bottom: 1px solid #eee;
            }

            .layui-form .order_goods_list thead th, .layui-form #order_goods_list tbody tr {
                border-bottom: 1px solid #E6E6E6;
            }

            .layui-form .order_goods_list thead th {
                background-color: #F5F5F5;
                line-height: 30px;
            }

            .layui-form .order_goods_list tbody td {
                line-height: 30px;
                padding: 8px 15px;
            }

            #order_goods_list_box{
                overflow: hidden;
            }

            #order_goods_list_box table{
                margin: 0;
            }

            #order_goods_list_box table:nth-of-type(2){
                display: block;
                overflow: auto;
                max-height: 300px;
            }

            .order-delivery .input-text {
                height: auto;
                min-height: 34px;
            }
            .edit-delivery-box table{
                margin: 0;
            }
            .edit-delivery-box table:last-of-type{
                display: block;
                height: 430px;
                overflow: auto;
            }
            .delivery-goods {
                max-height: 200px;
                overflow-y: scroll;
            }
            .delivery-goods::-webkit-scrollbar {
                display: none;
            }
            .delivery-goods tr td {
                padding: 8px 0;
            }
            .order-delivery .tips{
                margin-bottom: 20px;
            }
        </style>
        <!--发货订单弹出框-->
        <script type="text/html" id="order_delivery_html">
            <div class="order-delivery">
                <div class="layui-form">
                    {{# if(d.isTradeManaged){ }}
                    <div class="tips text-color">
                        <p>您已开通微信小程序发货信息管理服务，平台会将发货信息以消息的形式推送给购买的微信用户。</p>
                        <p>注意：每个订单只能更新一次发货信息，请谨慎操作！</p>
                    </div>
                    {{# } }}

                    <input type="hidden" name="type" value="manual">

                    <div class="layui-form-item">
                        <label class="layui-form-label">收货地址：</label>
                        <div class="layui-input-block">
                            <p class="input-text len-long"> {{ d.order_info.full_address }}{{ d.order_info.address }}</p>
                        </div>
                    </div>

                    <div class="layui-form-item delivery-type">
                        <label class="layui-form-label">发货方式：</label>
                        <div class="layui-input-block">
                            <input type="radio" lay-filter="delivery_type" name="delivery_type" value="1" title="物流发货" checked>
                            <input type="radio" lay-filter="delivery_type" name="delivery_type" value="0" title="无需物流">
                        </div>
                    </div>

                    <div class="express-type">
                        <div class="layui-form-item logistics-company">
                            <label class="layui-form-label">物流公司：</label>
                            <div class="layui-input-block len-mid">
                                <select name="express_company_id" lay-search lay-filter="express_company">
                                    <option value="">请选择物流公司</option>
                                    {{# layui.each(d.express_company, function(index, item){ }}
                                    <option value="{{ item.company_id }}">{{ item.company_name }}</option>
                                    {{# }); }}
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item express-number">
                            <label class="layui-form-label">快递单号：</label>
                            <div class="layui-input-block">
                                <input type="text" name="delivery_no" placeholder="" autocomplete="off" class="layui-input len-mid">
                            </div>
                        </div>
                    </div>

                    <div class="form-row">
                        <button type="button" class="layui-btn" lay-submit id="button_delivery_order" lay-filter="button_delivery_order" style="display:none;">保存</button>
                    </div>

                    <div id="order_goods_list_box">
                        <table class="layui-table order_goods_list" lay-filter="order_goods" lay-skin="line" lay-filter="order_goods_list">
                            <colgroup>
                                <col width="5%">
                                <col width="29%">
                                <col width="15%">
                                <col width="24%">
                                <col width="13%">
                                <col width="14%">
                            </colgroup>
                            <thead>
                            <tr>
                                <th style="text-align: center;"><input type="checkbox" lay-skin="primary" lay-filter="selectAllTop"/></th>
                                <th>商品名称</th>
                                <th>数量</th>
                                <th>物流单号</th>
                                <th>物流状态</th>
                                <th>退款状态</th>
                            </tr>
                            </thead>
                        </table>
                        <div class="delivery-goods">
                            <table class="layui-table order_goods_list" lay-filter="order_goods" lay-skin="line">
                                <colgroup>
                                    <col width="5%">
                                    <col width="29%">
                                    <col width="15%">
                                    <col width="24%">
                                    <col width="13%">
                                    <col width="14%">
                                </colgroup>
                                <tbody>
                                {{# layui.each(d.order_goods_list, function(index, item){ }}
                                <tr>
                                    <td style="text-align: center;">
                                        <!-- 未申请 已拒绝 部分退款 才可以发货 -->
                                        <input type="checkbox" lay-skin="primary" class="order_goods_id" lay-filter="select{{ item.order_goods_id }}" value="{{ item.order_goods_id }}" data-delivery-status="{{ item.delivery_status }}" {{# if(item.delivery_status == 1 || [0,-1,-3].indexOf(Number(item.refund_status)) == -1){ }} disabled {{# } }}/>
                                    </td>
                                    <td>{{ item.sku_name }} {{item.delivery_status}}</td>
                                    <td>{{ item.num }}</td>
                                    <td>{{ item.delivery_no }}</td>
                                    <td>{{ item.delivery_status_name }}</td>
                                    <td>{{ item.refund_status_name ? item.refund_status_name : '' }}</td>
                                </tr>
                                {{# }); }}
                                {{# if(d.order_goods_list.length === 0){ }}
                                <tr>
                                    <td colspan="5" align="center">无数据</td>
                                </tr>
                                {{# } }}
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </script>

        <!-- 批量订单发货 -->
        <script type="text/html" id="order_batch_delivery_html">
            <div class="order-delivery">
                <div class="layui-form">
                    {{# if(d.isTradeManaged){ }}
                    <div class="tips text-color">
                        <p>您已开通微信小程序发货信息管理服务，平台会将发货信息以消息的形式推送给购买的微信用户。</p>
                        <p>注意：每个订单只能更新一次发货信息，请谨慎操作！</p>
                    </div>
                    {{# } }}

                    <input type="hidden" name="type" value="manual">

                    <input type="hidden" name="sheet_exists" value="2">

                    <div class="layui-form-item  delivery-type">
                        <label class="layui-form-label">发货方式：</label>
                        <div class="layui-input-inline">
                            <input type="radio" lay-filter="delivery_type" name="delivery_type" value="1" title="物流发货" checked>
                            <input type="radio" lay-filter="delivery_type" name="delivery_type" value="0" title="无需物流">
                        </div>
                    </div>


                    <div class="express-type">
                        <div class="layui-form-item logistics-company ">
                            <label class="layui-form-label">物流公司：</label>
                            <div class="layui-input-block len-mid">
                                <select name="express_company_id" lay-search lay-filter="express_company">
                                    <option value="">请选择物流公司</option>
                                    {{# layui.each(d.express_company, function(index, item){ }}
                                    <option value="{{ item.company_id }}">{{ item.company_name }}</option>
                                    {{# }); }}
                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="form-row">
                        <button type="button" class="layui-btn" lay-submit id="button_delivery_order" lay-filter="button_delivery_order" style="display:none;">保存</button>
                    </div>

                    <div id="order_goods_list_box">
                        <table class="layui-table order_goods_list" lay-filter="order_goods" lay-skin="line">
                            <colgroup>
                                <col>
                                <col width="30%">
                                <col width="50%">
                                <col width="20%">
                            </colgroup>
                            <thead>
                            <tr>
                                <th></th>
                                <th>订单号</th>
                                <th>收货地址</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                        </table>

                        <table class="layui-table order_goods_list" lay-filter="order_goods" lay-skin="line">
                            <colgroup>
                                <col width="">
                                <col width="30%">
                                <col width="50%">
                                <col width="20%">
                            </colgroup>
                            <tbody>
                            {{# layui.each(d.order_goods_list, function(index, item){ }}
                            <tr>
                                <td></td>
                                <td>{{ item.order_no }}</td>
                                <td>{{ item.full_address }}</td>
                                <td><a href="javascript:;" class="text-color goods-item-remove" data-order-id="{{item.order_id}}">删除</a></td>
                            </tr>
                            {{# }); }}
                            {{# if(d.order_goods_list.length === 0){ }}
                            <tr>
                                <td colspan="3" align="center">无数据</td>
                            </tr>
                            {{# } }}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </script>

        <!-- 修改物流单号 -->
        <script type="text/html" id="order_edit_delivery">
            <div class="edit-delivery-box layui-form">
                <table class="layui-table">
                    <colgroup>
                        <col width="30%">
                        <col width="30%">
                        <col width="40%">
                    </colgroup>
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>物流公司</th>
                        <th>快递单号</th>
                    </tr>
                    </thead>
                </table>
                <table class="layui-table">
                    <colgroup>
                        <col width="30%">
                        <col width="30%">
                        <col width="40%">
                    </colgroup>
                    <tbody>
                    {{#for(var i = 0; i < d.editDeliveryData.length; i++){ }}
                    <tr>
                        <td>{{d.editDeliveryData[i].id}}</td>
                        <td>
                            <select>
                                {{#for(var j = 0; j < d.express_company.length; j++){ }}
                                {{# if(d.express_company[j].company_id == d.editDeliveryData[i].express_company_id){ }}
                                <option selected value="{{d.express_company[j].company_id}}">{{d.express_company[j].company_name}}</option>
                                {{# }else{ }}
                                <option value="{{d.express_company[j].company_id}}">{{d.express_company[j].company_name}}</option>
                                {{# } }}
                                {{# } }}
                            </select>
                        </td>
                        <td>
                            <input type="text"  class="layui-input" value="{{d.editDeliveryData[i].delivery_no}}">
                        </td>
                    </tr>
                    {{# } }}
                    </tbody>
                </table>
            </div>
        </script>

        <script>
            // 订单发货
            function orderDelivery(order_id) {
                var submitting = false;
                var order_info = getOrderInfo(order_id);
                var product_arr = [];

                layui.use(['table', 'form', 'laytpl'], function () {
                    var laytpl = layui.laytpl, table = layui.table, form = layui.form;
                    form.render();
                    var getTpl = $("#order_delivery_html").html();
                    var data = {order_info: order_info,express_company:express_company_list,isTradeManaged:isTradeManaged};
                    data.order_goods_list = order_info.order_goods;

                    laytpl(getTpl).render(data, function (html) {
                        layer.open({
                            type: 1,
                            shadeClose: true,
                            shade: 0.3,
                            fixed: false,
                            scrollbar: false,
                            title: "订单发货",
                            area: '800px',
                            btn: ['保存'],
                            yes: function (index, layero) {
                                $("#button_delivery_order").click();
                            },
                            content: html,
                            cancel: function (index, layero) {
                                layer.close(index);
                            },
                            success: function (layero, index) {
                                form.render();
                                form.on('radio(delivery_type)', function (data) {
                                    if (data.value == 1) {
                                        $(".express-type").show();
                                    } else {
                                        $(".express-type").hide();
                                    }

                                });

                                form.on('submit(button_delivery_order)', function (data) {
                                    var express_company_id = data.field.express_company_id;
                                    var template_id = data.field.template_id;

                                    if (data.field.delivery_type == 1 && express_company_id <= 0) {
                                        layer.msg('请选择物流公司', {time: 2000, icon: 5});
                                        return;
                                    }

                                    if (data.field.delivery_no == "" && data.field.delivery_type == 1) {
                                        layer.msg('物流单号不能为空', {time: 2000, icon: 5});
                                        return;
                                    }

                                    var order_goods_id_array = [];
                                    var isSecondDelivery = false; // 是否二次发货
                                    var count =0;
                                    $(".order_goods_id").each(function (i) {
                                        var checked = $(this).prop("checked");
                                        var disabled = $(this).prop('disabled');
                                        if(disabled == false){
                                            count++;
                                        }
                                        if (checked) {
                                            order_goods_id_array.push($(this).val());
                                        }
                                        var deliveryStatus = $(this).attr('data-delivery-status');
                                        // 存在已发货商品，当前操作被视为二次发货
                                        if(deliveryStatus == 1){
                                            isSecondDelivery = true;
                                        }
                                    });

                                    if (order_goods_id_array == "") {
                                        layer.msg('请选择发货商品', {time: 2000, icon: 5});
                                        return;
                                    }

                                    if(isTradeManaged && isSecondDelivery && count != order_goods_id_array.length){
                                        layer.msg('请选择全部商品发货', {time: 2000, icon: 5});
                                        return;
                                    }

                                    var order_goods_ids = order_goods_id_array.toString();
                                    data.field.order_goods_ids = order_goods_ids;

                                    if (submitting) return false;
                                    submitting = true;
                                    $.ajax({
                                        type: "post",
                                        url: 'http://niu.co/shop/order/delivery.html',
                                        async: true,
                                        dataType: 'json',
                                        data: data.field,
                                        success: function (res) {
                                            layer.msg(res.message);
                                            if(res.code >= 0){
                                                layer.close(layer.index - 1);
                                                reloadList();
                                            }
                                            submitting = false;
                                        }
                                    })
                                });

                                // 监听全选
                                form.on('checkbox(selectAllTop)', function (data) {
                                    if (data.elem.checked) {
                                        $("tr .order_goods_id:checkbox").each(function () {
                                            if ($(this).attr("disabled") == undefined) {
                                                $(this).prop("checked", true);
                                            }
                                        });
                                    } else {
                                        $("tr .order_goods_id:checkbox").each(function () {
                                            $(this).prop("checked", false);
                                        });
                                    }
                                    form.render();
                                });

                                // 监听每一行的复选框
                                var len = $("tbody .order_goods_id").length;

                                for (var i = 0; i < len; i++) {
                                    var num = $(".order_goods_id").eq(i).val();

                                    form.on('checkbox(select' + num + ')', function (data) {
                                        if ($("tbody .order_goods_id:checked").length == len) {
                                            $("input[lay-filter='selectAllTop']").prop("checked", true);
                                        } else {
                                            $("input[lay-filter='selectAllTop']").prop("checked", false);
                                        }

                                        form.render();
                                    });
                                }

                                //复选框选中
                                table.on('checkbox(order_goods)', function (obj) {
                                    if (obj.type == "all") {
                                        var data = table.checkStatus('product_table');
                                        var checkbox_data = data.data;
                                        product_arr = [];
                                        if (obj.checked) {
                                            $.each(checkbox_data, function (index, itemobj) {
                                                product_arr.push(itemobj.order_goods_id);
                                            })

                                        }
                                    } else {
                                        if (obj.checked) {
                                            // if(index != -1){
                                            product_arr.push(obj.data.order_goods_id);
                                            // }
                                        } else {
                                            var index = $.inArray(obj.data.order_goods_id, product_arr);
                                            product_arr.splice(index, 1);
                                        }
                                    }

                                    $(".deliveryed_count").text(product_arr.length);
                                });

                            }

                        });
                    })
                })

            }

            // 批量发货
            function orderBatchDelivery(order_data) {
                layui.use(['form', 'laytpl'], function () {
                    var batchSubmitting = false;
                    var laytpl = layui.laytpl, form = layui.form;
                    form.render();
                    var getTpl = $("#order_batch_delivery_html").html();
                    var data = {order_goods_list: order_data,express_company:express_company_list,isTradeManaged:isTradeManaged};
                    laytpl(getTpl).render(data, function (html) {
                        layer.open({
                            type: 1,
                            shadeClose: true,
                            shade: 0.3,
                            fixed: false,
                            scrollbar: false,
                            title: "订单发货",
                            area: '800px',
                            btn: ['保存'],
                            yes: function (index, layero) {
                                $("#button_delivery_order").click();
                            },
                            content: html,
                            cancel: function (index, layero) {
                                //右上角关闭回调
                                layer.close(index);
                                //return false 开启该代码可禁止点击该按钮关闭
                            },
                            success: function (layero, index) {

                                var sheetExists = $("input[name='sheet_exists']").val();

                                var deliveryModeIdent = "";
                                if (sheetExists == 1) {
                                    expressTemplate();
                                    deliveryModeIdent = "electronicsheet";
                                } else if (sheetExists == 2) {
                                    deliveryModeIdent = "manual";
                                }

                                $("#order_goods_list_box").html(tableContentChange(sheetExists));

                                form.render();
                                form.on('radio(delivery_type)', function (data) {
                                    if (data.value == 1) {
                                        $("#order_goods_list_box").html(tableContentChange(2));
                                        $(".express-type").show();
                                    } else {
                                        $("#order_goods_list_box").html(tableContentChange(1));
                                        $(".express-type").hide();
                                    }

                                });

                                form.on('radio(delivery_mode)', function (data) {
                                    deliveryModeIdent = data.value;
                                    if (data.value == "electronicsheet") {
                                        $(".express-mode").removeClass("layui-hide");
                                        $(".express-number").addClass("layui-hide");
                                        $(".delivery-type").addClass("layui-hide");
                                        $(".logistics-company").addClass("layui-hide");
                                        $("#order_goods_list_box").html(tableContentChange(1))
                                    } else if (data.value == "manual") {
                                        $(".express-mode").addClass("layui-hide");
                                        $(".express-number").removeClass("layui-hide");
                                        $(".logistics-company").removeClass("layui-hide");
                                        $(".delivery-type").removeClass("layui-hide");
                                        $("#order_goods_list_box").html(tableContentChange(2))
                                    }
                                });

                                $("body").off("click", ".order_goods_list:eq(1) .goods-item-remove").on("click", ".order_goods_list:eq(1) .goods-item-remove", function () {

                                    $(this).parents("tr").remove();
                                    var orderId = $(this).attr("data-order-id");

                                    for (var i=0;i<data.order_goods_list.length;i++){
                                        if(data.order_goods_list[i].order_id == orderId){
                                            data.order_goods_list.splice(i,1);
                                            break;
                                        }
                                    }

                                    var html = '<tr>';
                                    html += '<td colspan="5" align="center">无数据</td>';
                                    html += '</tr>';

                                    if (!$(".order_goods_list:eq(1) tbody").text().trim()) {
                                        $(".order_goods_list:eq(1) tbody").html(html)
                                    }
                                });

                                form.on('submit(button_delivery_order)', function (data) {
                                    var express_company_id = data.field.express_company_id;
                                    var template_id = data.field.template_id;
                                    if (template_id <= 0 && deliveryModeIdent == "electronicsheet") {
                                        layer.msg('请选择面单模版', {time: 2000, icon: 5});
                                        return;
                                    }

                                    if (data.field.delivery_type == 1 && express_company_id <= 0 && deliveryModeIdent == "manual") {
                                        layer.msg('请选择物流公司', {time: 2000, icon: 5});
                                        return;
                                    }

                                    var order_list = [];
                                    for (var orderItem = 0; orderItem < $(".order_goods_list:eq(1) tbody tr").length; orderItem++) {
                                        var json = {order_id: '', delivery_no: ''};
                                        json.order_id = $(".order_goods_list:eq(1) tbody tr").eq(orderItem).find(".goods-item-remove").attr("data-order-id");
                                        if ($(".order_goods_list:eq(1) tbody tr").eq(orderItem).find("input").length) {
                                            json.delivery_no = $(".order_goods_list:eq(1) tbody tr").eq(orderItem).find("input").val();
                                        }
                                        order_list.push(json);
                                    }

                                    data.field.order_list = order_list;

                                    if (batchSubmitting) return false;
                                    batchSubmitting = true;

                                    $.ajax({
                                        type: "post",
                                        url: 'http://niu.co/shop/delivery/batchdelivery.html',
                                        async: true,
                                        dataType: 'json',
                                        data: data.field,
                                        success: function (res) {

                                            layer.msg(res.message);
                                            if(res.code == 0){
                                                layer.close(layer.index - 1);
                                                reloadList();
                                            }
                                            batchSubmitting = false;
                                        }
                                    })
                                });

                                form.verify({
                                    required: function (value, item) {
                                        if (!value) {
                                            return '物流单号为空';
                                        }
                                    }
                                });

                                function tableContentChange(type) {
                                    var html = '<table class="layui-table order_goods_list" lay-filter="order_goods" lay-skin="line">';
                                    html += '<colgroup>';
                                    if (type == 2) {
                                        html += '<col width="20%">';
                                        html += '<col width="40%">';
                                        html += '<col width="20%">';
                                        html += '<col width="20%">';
                                    } else if (type == 1) {
                                        html += '<col>';
                                        html += '<col width="30%">';
                                        html += '<col width="50%">';
                                        html += '<col width="20%">';
                                    }
                                    html += '</colgroup>';

                                    html += '<thead>';
                                    if (type == 2) {
                                        html += '<tr>';
                                        html += '<th>订单号</th>';
                                        html += '<th>收货地址</th>';
                                        html += '<th>物流单号</th>';
                                        html += '<th>操作</th>';
                                        html += '</tr>';
                                    } else if (type == 1) {
                                        html += '<tr>';
                                        html += '<th></th>';
                                        html += '<th>订单号</th>';
                                        html += '<th>收货地址</th>';
                                        html += '<th>操作</th>';
                                        html += '</tr>';
                                    }
                                    html += '</thead>';
                                    html += '</table>';

                                    html += '<table class="layui-table order_goods_list" lay-filter="order_goods" lay-skin="line">';
                                    html += '<colgroup>';
                                    if (type == 2) {
                                        html += '<col width="20%">';
                                        html += '<col width="40%">';
                                        html += '<col width="20%">';
                                        html += '<col width="20%">';
                                    } else if (type == 1) {
                                        html += '<col>';
                                        html += '<col width="30%">';
                                        html += '<col width="50%">';
                                        html += '<col width="20%">';
                                    }
                                    html += '</colgroup>';
                                    html += '<tbody>';
                                    if (data.order_goods_list.length > 0) {
                                        for (var i = 0; i < data.order_goods_list.length; i++) {
                                            if (type == 2) {
                                                html += '<tr>';
                                                html += `<td>${data.order_goods_list[i].order_no}</td>`;
                                                html += `<td>${data.order_goods_list[i].full_address}</td>`;
                                                html += `<td><input lay-verify="required" class="layui-input" type="text"></td>`;
                                                html += `<td><a href="javascript:;" class="text-color goods-item-remove" data-order-id="${data.order_goods_list[i].order_id}">删除</a></td>`;
                                                html += '</tr>';
                                            } else if (type == 1) {
                                                html += '<tr>';
                                                html += `<td></td>`;
                                                html += `<td>${data.order_goods_list[i].order_no}</td>`;
                                                html += `<td>${data.order_goods_list[i].full_address}</td>`;
                                                html += `<td><a href="javascript:;" class="text-color goods-item-remove" data-order-id="${data.order_goods_list[i].order_id}">删除</a></td>`;
                                                html += '</tr>';
                                            }
                                        }
                                    } else {
                                        html += '<tr>';
                                        html += `<td colspan="4" align="center">无数据</td>`;
                                        html += '</tr>';
                                    }
                                    html += '</tbody>';

                                    html += '</table>';

                                    return html;
                                }
                            }

                        });
                    })
                })
            }

            // 电子面单模版
            function expressTemplate() {
                $.ajax({
                    type: "post",
                    url: ("shop/delivery/getexpresselectronicsheetlist"),
                    dataType: 'json',
                    success(res) {
                        if (res.code >= 0) {
                            var templateList = res.data;
                            var html = '';
                            html += '<select name="template_id" lay-search lay-filter="express_company">';
                            html += '<option value="">请选择面单模版</option>';
                            for (var i = 0; i < templateList.length; i++) {
                                html += '<option value=' + templateList[i].id + '>' + templateList[i].template_name + '</option>';
                            }
                            html += '</select>';
                            $(".express-mode div").html(html);
                            form.render();
                        }
                    }
                })
            }

            // 修改物流单号
            function editDelivery(order_id) {
                var data = {};
                // 物流信息
                $.ajax({
                    type: "post",
                    url: ("shop/delivery/getOrderDelivery"),
                    data:{order_id:order_id},
                    dataType: 'json',
                    async: false,
                    success:function(res) {
                        if (res.code >= 0) {
                            data.editDeliveryData = res.data;
                        }else{
                            layer.msg(layer.msg(res))
                        }
                    }
                });

                data.express_company = express_company_list; // 物流公司
                var submitIdent = false;

                laytpl($("#order_edit_delivery").html()).render(data, function(html) {
                    layer.open({
                        title: '修改物流单号',
                        skin: 'layer-tips-class',
                        type: 1,
                        btn:['保存','取消'],
                        area: ['800px', '600px'],
                        content: html,
                        yes: function () {
                            var submitArr = [];
                            var nullIdent = false;
                            if (submitIdent){
                                submitIdent = true;
                                layer.msg("请勿重复保存");
                                return false;
                            }
                            $(".edit-delivery-box tbody tr").each(function (index,item) {
                                var arr = {};
                                if (!$(item).find("td").eq(1).find("select option:selected").val()){
                                    layer.msg("物流公司不能为空");
                                    nullIdent = true;
                                    return false;
                                }
                                if (!$(item).find("td").eq(2).find("input").val()){
                                    layer.msg("物流单号不能为空");
                                    nullIdent = true;
                                    return false;
                                }
                                arr.express_company_id = $(item).find("td").eq(1).find("select option:selected").val();
                                arr.id = $(item).find("td").eq(0).text();
                                arr.delivery_no = $(item).find("td").eq(2).find("input").val();
                                submitArr.push(arr);
                                nullIdent = false;
                            });

                            if (nullIdent){
                                return false;
                            }
                            submitArr = JSON.stringify(submitArr);

                            $.ajax({
                                type: "post",
                                url: ("shop/delivery/editOrderDelivery"),
                                dataType: 'json',
                                data:{delivery_json: submitArr},
                                success: function (res) {
                                    layer.msg(res.message);
                                    if(res.code == 0){
                                        layer.close(layer.index - 1);
                                        reloadList();
                                    }else{
                                        submitIdent = false;
                                    }

                                }
                            });
                        }
                    });
                });

                form.render();
            }
        </script>

        <!-- 主动退款 -->
        <style>
            .refund-view-list{font-size:14px;line-height:20px;color:#323233;color:var(--theme-stroke-1,#323233)}
            .refund-view-item {margin-bottom: 10px;}
            .refund-view-item-label{width:75px; vertical-align: top;}
            .refund-view-item-content{display:inline-block}
            .refund-view-list .word-aux{margin-left:74px;}
        </style>
        <!-- 店铺主动退款 -->
        <script type="text/html" id="refund_transfer_html">
            <div style="padding:10px;">
                <div class="layui-form refund-transfer-html" id='refund_transfer'lay-filter="refund_transfer">
                    <div class="refund-view-list">
                        <div class="refund-view-item">
                            <label class="refund-view-item-label">退款金额：</label>
                            <div class="refund-view-item-content">
                                <span class="refund-money">￥{{ d.order_goods_info.refund_apply_money }}</span>
                            </div>
                        </div>
                        <div class="refund-view-item">
                            <label class="refund-view-item-label">主动退款：</label>
                            <div class="refund-view-item-content">
                                <input type='number' class="layui-input" name="shop_active_refund_money" value="" placeholder="0.00">
                            </div>
                            <div class="word-aux">
                                <div>1、如果退全部金额，则该订单项将关闭，无法再进行收发货等操作</div>
                                <div>2、否则，订单项只是进入部分退款状态，后续还可以正常的收发货</div>
                            </div>
                        </div>
                        <div class="refund-view-item">
                            <label class="refund-view-item-label">退款方式：</label>
                            <div class="refund-view-item-content">
                                <input type="radio" title="原路退款" checked name="shop_active_refund_money_type" value="1">
                                <input type="radio" title="线下退款"  name="shop_active_refund_money_type" value="2">
                                <input type="radio" title="退款到余额"  name="shop_active_refund_money_type" value="3">
                            </div>
                        </div>
                        <div class="refund-view-item">
                            <label class="refund-view-item-label">退款说明：</label>
                            <div class="refund-view-item-content">
                                <textarea name="shop_active_refund_remark" class="layui-textarea len-long" maxlength="150"></textarea>
                            </div>
                        </div>

                    </div>
                    <input type="hidden" name="order_goods_id" value="{{ d.order_goods_info.order_goods_id }}"/>
                    <button class="layui-btn"  lay-submit id="submit_transfer" lay-filter="submit_transfer" style="display:none;">保存</button>
                </div>
            </div>
        </script>

        <script>
            var laytpl,form,active_refund_layer;
            layui.use(['laytpl','form'], function(){
                laytpl = layui.laytpl;
                form = layui.form;
                form.render();
            });

            // 主动退款
            function shopActiveRefund(order_goods_id) {
                $.ajax({
                    url: ("shop/orderrefund/getOrderGoodsRefundInfo"),
                    type: "POST",
                    dataType: "JSON",
                    async: false,
                    data: {order_goods_id: order_goods_id},
                    success: function (res) {
                        if (res.code >= 0) {
                            var getTpl = $("#refund_transfer_html").html();
                            var data = res.data;
                            laytpl(getTpl).render(data, function (html) {
                                active_refund_layer = layer.open({
                                    type: 1,
                                    shadeClose: true,
                                    shade: 0.3,
                                    offset: 'auto',
                                    scrollbar: true,
                                    fixed: false,
                                    title: "店铺主动退款",
                                    area: ['700px', 'auto'],
                                    btn: ['确认退款', '取消'],
                                    yes: function (index, layero) {
                                        $("#submit_transfer").click();
                                    },
                                    btn2: function (index, layero) {
                                        layer.close(index);
                                    },
                                    content: html,
                                    success: function (layero, index) {
                                        var repeat_flag = false;//防重复标识
                                        form.render();

                                        form.on('submit(submit_transfer)', function (data) {

                                            if (repeat_flag) return;
                                            repeat_flag = true;
                                            $.ajax({
                                                url: ("shop/orderrefund/shopActiveRefund"),
                                                type: "POST",
                                                dataType: "JSON",
                                                async: false,
                                                data: data.field,
                                                success: function (res) {
                                                    layer.msg(res.message);
                                                    if (res.code == 0) {
                                                        layer.close(active_refund_layer);
                                                        reloadList();
                                                    } else {
                                                        repeat_flag = false;
                                                    }

                                                }
                                            });
                                            return false;
                                        });
                                    }
                                });
                                form.render();
                            });
                        } else {
                            layer.msg(res.message);
                        }
                    }
                });

            }
        </script>
        <!--打印相关-->
        <script type="text/html" id="express_sheet_html">
            <div class="layui-form express-sheet">
                <div class="layui-form-item express-mode">
                    <label class="layui-form-label"><span class="required">*</span>面单模版：</label>
                    <div class="layui-input-block len-mid">
                        <select name="template_id" lay-search lay-filter="express_company" lay-verify="required">
                            <option value="">请选择面单模版</option>
                            {{#  layui.each(d, function(index, item){ }}
                            <option value="{{ item.id }}"  {{#  if(item.is_default === 1){ }} selected {{#  } }} >{{ item.template_name }}</option>
                            {{#  }); }}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">是否发货</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="is_delivery" lay-skin="switch" value="1">
                    </div>
                </div>
                <div class="form-row">
                    <button type="button" class="layui-btn" lay-submit lay-filter="express_sheet_save">点击确定</button>
                </div>
            </div>
        </script>

        <script type="text/html" id="again_express_sheet_html">
            <div class="layui-form express-sheet">
                <div class="layui-form-item express-mode">
                    <label class="layui-form-label"><span class="required">*</span>面单模版：</label>
                    <div class="layui-input-block len-mid">
                        <select name="template_id" lay-search lay-filter="express_company" lay-verify="required">
                            <option value="">请选择面单模版</option>
                            {{#  layui.each(d, function(index, item){ }}
                            <option value="{{ item.id }}"  {{#  if(item.is_default === 1){ }} selected {{#  } }} >{{ item.template_name }}</option>
                            {{#  }); }}
                        </select>
                    </div>
                </div>
                <div class="form-row">
                    <button type="button" class="layui-btn" lay-submit lay-filter="express_sheet_save">点击确定</button>
                </div>
            </div>
        </script>

        <script>
            var expresselectronicsheetlist = [];

            //获取物流公司
            $.ajax({
                type: "post",
                url: ("shop/delivery/getexpresselectronicsheetlist"),
                dataType: 'json',
                success: function (res) {
                    if (res.code == 0) {
                        expresselectronicsheetlist = res.data;
                    }
                }
            });

            //打印电子面单
            function printElectronicsheetAction(order_id_list){
                var getTpl = $("#express_sheet_html").html();
                laytpl(getTpl).render(expresselectronicsheetlist, function(html) {
                    layer.open({
                        type: 1,
                        shadeClose: true,
                        shade: 0.3,
                        fixed: false,
                        scrollbar: false,
                        title: "打印电子面单",
                        area: '550px',
                        content: html,
                        success: function (layero, index) {
                            form.render();
                            form.on('submit(express_sheet_save)', function (data) {

                                $.each(order_id_list, function(index, value) {
                                    data.field.order_id = value;

                                    $.ajax({
                                        type: 'post',
                                        url: ("shop/delivery/printElectronicsheet"),
                                        dataType: 'JSON',
                                        data: data.field,
                                        success: function (res) {
                                            layer.msg(res.message);
                                            if (res.code >= 0) {
                                                expressSheet(res.data.PrintTemplate);
                                                listenerHash(); // 刷新页面
                                                layer.closeAll();
                                            }
                                        }
                                    });
                                });

                            });
                        }

                    });
                })
            }

            /**
             * 批量打印电子面单
             */
            function CreateTwoFormPage(html){
                LODOP=getLodop();
                if(LODOP) {
                    LODOP.PRINT_INIT("打印电子面单");
                    LODOP.ADD_PRINT_HTM(0, 10, "95%", "100%", html);
                }
            }

            function expressSheet(html) {
                CreateTwoFormPage(html);
                // LODOP.PREVIEW(); //预览
                LODOP.PRINT();  //直接打印
            }

            function orderPrintElectronicsheet(order_id){
                printElectronicsheetAction([order_id]);
            }

            // 重新打印电子面单
            function printElectronicsheet(order_id)
            {
                var getTpl = $("#again_express_sheet_html").html();
                laytpl(getTpl).render(expresselectronicsheetlist, function(html) {
                    layer.open({
                        type: 1,
                        shadeClose: true,
                        shade: 0.3,
                        fixed: false,
                        scrollbar: false,
                        title: "打印电子面单",
                        area: '550px',
                        content: html,
                        success: function (layero, index) {
                            form.render();
                            form.on('submit(express_sheet_save)', function (data) {
                                data.field.order_id = order_id;
                                $.ajax({
                                    type: 'post',
                                    url: ("shop/delivery/printElectronicsheet"),
                                    dataType: 'JSON',
                                    data: data.field,
                                    success: function (res) {
                                        layer.msg(res.message);
                                        if (res.code >= 0) {
                                            expressSheet(res.data.PrintTemplate);
                                            listenerHash(); // 刷新页面
                                            layer.closeAll();
                                        }
                                    }
                                });

                            });
                        }

                    });
                })
            }
        </script>

        <script src="http://niu.co/app/shop/view/public/js/lodop_funcs.js"></script>
        <script>
            $('.package-list li').click(function(){
                $(this).addClass('layui-this').siblings('li').removeClass('layui-this');
                $('.order-package-content .layui-tab-item:eq('+ $(this).index() +')').addClass('layui-show').siblings('.layui-tab-item').removeClass('layui-show');
            })

            function logisticsOperation(orderId,packageId,dataJson) {
                //获取模板
                var getTpl = $("#logistics_html").html();
                var data = {};
                data.dataJson = dataJson;
                $.ajax({
                    type: "post",
                    url: ("shop/express/getShopExpressCompanyList"),
                    dataType: 'json',
                    async: false,
                    success: function (res) {
                        if (res.code == 0) {
                            data.express_company = res.data;
                        }
                    }
                });
                laytpl(getTpl).render(data, function (html) {
                    layer.open({
                        type: 1,
                        shadeClose: true,
                        shade: 0.3,
                        fixed: false,
                        scrollbar: false,
                        title: "修改物流信息",
                        area: '800px',
                        content: html,
                        cancel: function (index, layero) {
                            //右上角关闭回调
                            layer.close(index);
                            //return false 开启该代码可禁止点击该按钮关闭
                        },
                        success: function (layero, index) {
                            form.render();
                            form.on('radio(delivery_type)', function (data) {
                                if (data.value == 1) {
                                    $(".express-type").removeClass("layui-hide");
                                } else {
                                    $(".express-type").addClass("layui-hide");
                                }

                            });
                            var submitting = false;
                            form.on('submit(button_logistics_order)', function (data) {
                                var express_company_id = data.field.express_company_id;
                                if (data.field.delivery_type == 1 && express_company_id <= 0) {
                                    layer.msg('请选择物流公司', {time: 2000, icon: 5});
                                    return;
                                }
                                if (data.field.delivery_no == "" && data.field.delivery_type == 1) {
                                    layer.msg('物流单号不能为空', {time: 2000, icon: 5});
                                    return;
                                }

                                if (submitting) return false;
                                submitting = true;

                                data.field.order_id = orderId;
                                data.field.package_id = packageId;
                                $.ajax({
                                    type: "post",
                                    url: 'http://niu.co/shop/delivery/editOrderDelivery.html',
                                    async: true,
                                    dataType: 'json',
                                    data: data.field,
                                    success: function (res) {
                                        layer.msg(res.message);
                                        if(res.code == 0){
                                            layer.close(layer.index - 1);
                                            reloadList();
                                        }
                                        submitting = false;
                                    }
                                })
                            });
                        }

                    });
                })
            }
        </script>
        <script type="text/html" id="logistics_html">
            <div class="order-delivery">
                <div class="layui-form">
                    <input type="hidden" name="type" value="manual">
                    <div class="layui-form-item delivery-type">
                        <label class="layui-form-label">发货方式：</label>
                        <div class="layui-input-block">
                            {{# if(d.dataJson.delivery_type == 1){ }}
                            <input type="radio" lay-filter="delivery_type" name="delivery_type" value="1" title="物流发货" checked>
                            <input type="radio" lay-filter="delivery_type" name="delivery_type" value="0" title='无需物流'>
                            {{# }else{ }}
                            <input type="radio" lay-filter="delivery_type" name="delivery_type" value="1" title="物流发货">
                            <input type="radio" lay-filter="delivery_type" name="delivery_type" value="0" title='无需物流' checked>
                            {{# } }}
                        </div>
                    </div>

                    {{# if(d.dataJson.delivery_type == 1){ }}
                    <div class="express-type">
                        {{# }else{ }}
                        <div class="express-type layui-hide">
                            {{# } }}
                            <div class="layui-form-item logistics-company">
                                <label class="layui-form-label">物流公司：</label>
                                <div class="layui-input-block len-mid">
                                    <select name="express_company_id" lay-search lay-filter="express_company">
                                        <option value="">请选择物流公司</option>
                                        {{# layui.each(d.express_company, function(index, item){ }}
                                        {{# if(item.company_id == d.dataJson.express_company_id){ }}
                                        <option value="{{ item.company_id }}" selected>{{ item.company_name }}</option>
                                        {{# }else{ }}
                                        <option value="{{ item.company_id }}">{{ item.company_name }}</option>
                                        {{# } }}
                                        {{# }); }}
                                    </select>
                                </div>
                            </div>

                            <div class="layui-form-item express-number">
                                <label class="layui-form-label">快递单号：</label>
                                <div class="layui-input-block">
                                    <input type="text" name="delivery_no" placeholder="" autocomplete="off" class="layui-input len-mid" value="{{d.dataJson.delivery_no}}">
                                </div>
                            </div>
                        </div>

                        <div class="form-row">
                            <button type="button" class="layui-btn" lay-submit lay-filter="button_logistics_order">保存</button>
                        </div>
                    </div>
                </div>
        </script>

    </div>


</div>